home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)tx2vt.c V1.11 5/2/95";
- #endif
- /* ====================================================================
- tx2vt - convert hardware texts to vector texts in a viewfile
- --------------------------------------------------------------------
- VERSION 1.0
- SYNOPSIS tx2vt <device-string> <viewfile-source> <viewfile-destination> [<fontfile>] {[<fontheight> <fontwidth>] [<scale>]}
- DESCRIPTION Converts all hardware texts in a viewfile to software
- generated vector texts. Uses a new routine
- VOdrObReplace(). The regular roman.vf font is used
- unless otherwise specified and sizes are scaled to
- match the original hardware texts as closely as
- possible. The user should then be able to go into
- DV-Draw and make the appropriate fine changes if
- necessary. The utility will correctly convert all
- hardware texts in included subdrawings; referenced
- subdrawings will be left as is.
-
- HOW IT WORKS
-
- There are three possibilities requiring consideration in a
- view when converting:
-
- (1) if it is a regular text object (OT_TEXT):
- (a) create a version in vector text (VOvtCreate);
- (b) size it so that it will approximate the height and
- width of the regular text (VOtxBox, VOvtBox, VOvtAtSet);
- (c) replace the regular text with the vector text
- (using VOdrObReplace).
- (2) if it is a subdrawing (OT_SUBDRAWING), recursively do a
- TobForEachSubobject with the drawing object associated with
- the subdrawing.
- (3) if it is anything else, ignore it.
-
- EXAMPLE tx2vt console dan.v out.v gothen.vf
- ================================================================= */
-
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "VOstd.h"
- #include "VOfundecl.h"
- #include "Tfundecl.h"
-
- /* Global forward function declarations */
- int main V_P_ ((int argc, char *argv[]));
-
-
- #define ARGBLOCK argblock
- typedef struct
- {
- OBJECT d;
- char *f;
- } argblock;
-
- DRAWPORT drawport;
- FLOAT fh = 1, fw = 1, scale = 0;
- INT userset = 0;
-
- /* Local forward function declarations */
- ADDRESS ReplaceTextWithVtext V_P_ ((OBJECT object, argblock * arg));
- LOCAL char *VIstrclone V_P_ ((char *str));
-
- LOCAL CHAR ErrMsg[]= "Wrong number of arguments.\n";
- LOCAL CHAR Usage[]= "Usage: %s <device-string> <viewfile-source> <viewfile-destination>\n [<fontfile>] {[<fontheight> <fontwidth>] [<scale>]}\n";
- LOCAL CHAR *DVpath = NULL; /* Use value of DVPATH config variable */
-
- int
- main (argc, argv)
- int argc;
- char *argv[];
- {
- VIEW view;
- SCREEN_OBJECT screen;
- ARGBLOCK arg;
-
- /* Make sure there are at least 3 arguments */
- if (argc < 4)
- {
- (VOID) fprintf (stderr, ErrMsg);
- (VOID) fprintf (stderr, Usage, argv[0]);
- exit (EXIT_ERR);
- }
-
- /* Initialize program */
- (VOID) TInit (DVpath, (CHAR *) NULL);
- screen = TscOpen (argv[1], (CHAR *) NULL);
- view = TviLoad (argv[2]);
- drawport = TdpCreate (screen, view, (RECTANGLE *) NULL,
- (RECTANGLE *) NULL);
-
- /* Setup argument block to pass to TobForEachSubobject */
- arg.d = TviGetDrawing (view); /* arg.d is the drawing */
- if (argc >= 5) /* arg.f is the font name */
- arg.f = (char *) VIstrclone (argv[4]);
- else
- arg.f = (char *) VIstrclone ("roman.vf");
- if (argc == 6) /* font scale (uniform) */
- (VOID) sscanf (argv[5], "%f", &scale);
- if (argc == 7)
- { /* font height and width */
- userset = 1;
- (VOID) sscanf (argv[5], "%f", &fh);
- (VOID) sscanf (argv[6], "%f", &fw);
- }
-
- /* Recursively replace all regular text object */
- (VOID) TobForEachSubobject (arg.d,
- (TOBFOREACHSUBOBJFUNPTR)ReplaceTextWithVtext,
- (ADDRESS) & arg);
-
- /* Save new view file and clean-up */
- if (!TviSave (view, argv[3]))
- (VOID) fprintf (stderr, "%s: Could not save view\n", argv[3]);
- TdpFree (drawport);
- (VOID) TscClose (screen);
- (VOID) TTerminate ();
- return EXIT_OK;
- }
-
- ADDRESS
- ReplaceTextWithVtext (object, arg)
- OBJECT object;
- argblock *arg;
- {
- INT objtype;
- CHAR *string;
- OBJECT ptobj, vtobj;
- OBJECT drawing;
- DV_POINT scp, wcp, woff;
- ARGBLOCK subarg;
- ATTRIBUTES attr;
- RECTANGLE wvp, svp;
- OBJECT dyn_obj;
-
- /* The drawing object containing the current object is arg->d */
- drawing = arg->d;
-
- /* If it is of text type replace it with vector text,
- else if it is a subdrawing, descend recursively and repeat,
- else just ignore. */
- if ((objtype = VOobType (object)) == OT_TEXT)
- {
- /* construct a close match of regular text with vector text */
- ptobj = VOobPtGet (object, 1);
- VOobAtGet (object, &attr);
- attr.text_fontname = (char *) VIstrclone (arg->f);
- attr.text_width = fw;
- attr.text_height = fh;
- attr.text_angle = attr.text_slant = 0;
- attr.text_charspace = attr.text_linespace = 0;
- string = (char *) VIstrclone (VOtxGetString (object));
- vtobj = VOvtCreate (string, VOobClone (ptobj), &attr);
- if (!userset)
- {
- VOobBox (object, &wvp, &svp);
- scp.x = DV_VIABS (svp.ur.x - svp.ll.x);
- scp.y = DV_VIABS (svp.ur.y - svp.ll.y);
- (VOID) TdpScreenToWorld (drawport, &scp, &wcp);
- scp.x = 0;
- scp.y = 0;
- (VOID) TdpScreenToWorld (drawport, &scp, &woff);
- attr.text_width = wcp.x - woff.x;
- attr.text_height = wcp.y - woff.y;
- VOobBox (vtobj, &wvp, &svp);
- attr.text_width /= DV_VIABS (wvp.ur.x - wvp.ll.x);
- attr.text_height /= DV_VIABS (wvp.ur.y - wvp.ll.y);
- if (scale)
- {
- attr.text_width *= scale;
- attr.text_height *= scale;
- }
- VOobAtSet (vtobj, &attr);
- }
- dyn_obj = VOobDyGet (object);
- if (dyn_obj)
- VOobDySet (vtobj, dyn_obj);
-
- (VOID) VOdrObReplace (drawing, object, vtobj); /* replace! */
-
-
- }
- else if (objtype == OT_SUBDRAWING)
- {
- /* descend recursively if the object happens to be a subdrawing
- and search again for regular text to replace */
- subarg.d = VOsdDrGet (object);
- subarg.f = (char *) VIstrclone (arg->f);
- (VOID) TobForEachSubobject (subarg.d,
- (TOBFOREACHSUBOBJFUNPTR)ReplaceTextWithVtext,
- (ADDRESS) & subarg);
- }
- return NULL;
- }
-
- LOCAL char *
- VIstrclone (str)
- char *str;
- {
- INT len;
- CHAR *newstr;
-
- if (str == NULL)
- return (NULL);
- len = S_STRLEN (str) + 1;
- newstr = (CHAR *) S_ALLOC (len);
- (VOID) strcpy (newstr, str);
- return (newstr);
- }
-
- /* DD -----------------------------> end of tx2vt.c ---------------- */
-